`
https://leetcode.cn/problems/even-odd-tree/
`

/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {boolean}
 */
var isEvenOddTree = function (root) {
  const q = [root]
  // 表示当前层应该是什么状态
  // true 表示当前层应该是奇整数，严格递增
  // false 表示当前层应该是偶整数，严格递减
  let isOdd = true

  while (q.length) {
    const sz = q.length
    let lastNode = null
    for (let i = 0; i < sz; i++) {
      const cur = q.shift()
      if (isOdd) {
        if (cur.val % 2 === 0) return false
        if (lastNode && cur.val <= lastNode.val) return false
      } else {
        if (cur.val % 2 === 1) return false
        if (lastNode && cur.val >= lastNode.val) return false
      }
      if (cur.left) q.push(cur.left)
      if (cur.right) q.push(cur.right)
      lastNode = cur
    }
    isOdd = !isOdd
  }
  return true
};